﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QLKSOrange
{
    public partial class ThemNhanVienMoi : Form
    {
        linqQLKhachSanDataContext dataQLKS = new linqQLKhachSanDataContext();
        public ThemNhanVienMoi()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ThemNhanVienMoi_Load(object sender, EventArgs e)
        {
          
            var dsBoPhan = dataQLKS.sp_DSBoPhan();
            comboBoxBoPhan.DataSource = dsBoPhan;
            comboBoxBoPhan.DisplayMember = "Ten";
            comboBoxBoPhan.ValueMember = "Ma";
            var dsTienTe = dataQLKS.sp_DSTienTe();
            cmbTienTe.DataSource = dsTienTe;
            cmbTienTe.DisplayMember = "Ten";
            cmbTienTe.ValueMember = "Ma";

            string mabophan = comboBoxBoPhan.SelectedValue.ToString();
            var dsNhanVien = dataQLKS.sp_DSNhanVien_BoPhan(mabophan);
            dgvNguoiQuanLy.DataSource = dsNhanVien;
        }

        private void comboBoxBoPhan_SelectedIndexChanged(object sender, EventArgs e)
        {
            string mabophan = comboBoxBoPhan.SelectedValue.ToString();
            var dsNhanVien = dataQLKS.sp_DSNhanVien_BoPhan(mabophan);
            dgvNguoiQuanLy.DataSource = dsNhanVien;
            dgvNguoiQuanLy.Enabled = true;

        }


        private void dgvNguoiQuanLy_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dgvNguoiQuanLy.CurrentRow.Index;
            string maNV = dgvNguoiQuanLy.Rows[index].Cells[0].Value.ToString();
            string tenNV = dgvNguoiQuanLy.Rows[index].Cells[1].Value.ToString();
            textBoxMaQuanLy.Text = maNV;
            textBoxTenQuanLy.Text = tenNV;
        }
        private void dgvNguoiQuanLy_RowHeaderMouseClick(object sender, DataGridViewCellEventArgs e)
        { }
     //   int KTThongTin
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (KTThongTinDayDu() == 0)
            {
                MessageBox.Show("Thông tin không đầy đủ");
                return;
            }
    
            string ten = txtTen.Text.ToString();
            DateTime ngaysinh = dtpNgaySinh.Value.Date;
            string diachi = txtDiaChi.Text.ToString();
            string dienthoai = txtDienThoai.Text.ToString();
            string cmnd = txtCMND.Text.ToString();
            string phai;
            if (rbtNam.Checked == true)
                phai = "Nam";
            else
                phai = "Nữ";
            string mabophan = comboBoxBoPhan.SelectedValue.ToString();
            string maNQL = textBoxMaQuanLy.Text.ToString();
            

            //Thêm bảng luong

            float luongCB = float.Parse(txtLuongCB.Text.ToString());
            float trocap = float.Parse(txtTroCap.Text.ToString()); 
            float hoahong = float.Parse(txtHoaHong.Text.ToString());
            int songaynghi = int.Parse(txtSoNgayNghi.Text.ToString());
            string DVTT = cmbTienTe.SelectedValue.ToString();

            dataQLKS.sp_ThemNhanVien(ten, ngaysinh, diachi, dienthoai, cmnd, phai, mabophan, maNQL, luongCB, trocap, hoahong, songaynghi, DVTT);

            MessageBox.Show("Thêm thành công");
            textBoxMaQuanLy.Text = "";
            textBoxTenQuanLy.Text = "";
            txtCMND.Text = "";
            txtDiaChi.Text = "";
            txtDienThoai.Text = "";
            txtHoaHong.Text = "";
            txtLuongCB.Text = "";
            txtSoNgayNghi.Text = "";
            txtTen.Text = "";
            txtTroCap.Text = "";
            

        }

        int KTThongTinDayDu()
        {
           if(  textBoxMaQuanLy.Text == "" ||
                textBoxTenQuanLy.Text == ""||
                txtCMND.Text == ""||
                txtDiaChi.Text == ""||
                txtDienThoai.Text == ""||
                txtHoaHong.Text ==""||
                txtLuongCB.Text == ""||
                txtSoNgayNghi.Text == ""||
                txtTen.Text == ""||
                txtTroCap.Text == "")
                return 0;
           return 1;

        }
      
    }
}